package com.das.mechanic_base.adapter.camera;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.camera.TagDetectionBean;
import com.kproduce.roundcorners.RoundTextView;

import java.util.List;

public class X3TagDetectionItemAdapter extends RecyclerView.Adapter<X3TagDetectionItemAdapter.TagDetectionItemHolder> {

    private List<TagDetectionBean.TagOptionBean> mList;

    private Context mContext;

    public X3TagDetectionItemAdapter(List<TagDetectionBean.TagOptionBean> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public TagDetectionItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new TagDetectionItemHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_tag_detection_item_view,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull TagDetectionItemHolder holder, int position) {
        holder.rv_title.setText(mList.get(position).optionDescription);

        holder.rv_title.setOnClickListener(v -> {
            if (iOnClickItem != null) {
                iOnClickItem.iOnClickItem(mList.get(position).optionDescription);
            }
        });

    }

    IOnClickItem iOnClickItem;

    public X3TagDetectionItemAdapter setiOnClickItem(IOnClickItem iOnClickItem) {
        this.iOnClickItem = iOnClickItem;
        return this;
    }

    public interface IOnClickItem {
        void iOnClickItem(String content);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class TagDetectionItemHolder extends RecyclerView.ViewHolder {
        RoundTextView rv_title;
        public TagDetectionItemHolder(@NonNull View itemView) {
            super(itemView);
            rv_title = itemView.findViewById(R.id.rv_title);
        }
    }
}
